package day4;

import java.lang.reflect.Field;
import java.util.Date;
//获取属性
public
class Per extends Animal {
    String name;
    protected double money;
    private Integer id;
    public Per(Integer id) {
        this.id = id;
        System.out.println("有参构造器");
    }
    private Per() {
        System.out.println("无参构造器");
    }
    public Date birthday;
    public void test1(){
        System.out.println("运行test1");
    }
    private void test2(String name,Integer num){
        System.out.println("运行test2:"+name+" "+num);
    }
    public int test3(int a,int b){
        System.out.println("运行test3:"+a+" "+b);
        return a+b;
    }

}
class Animal{
    private String height;
    int age;
    protected String sex;
    public String addr;
}
class a {
    public static
    void main(String[] args) {
        Per per = new Per(10);
        Class<?> c = per.getClass();

        //2.通过类对象调用getXX() 调用类资源
        String name = c.getName();
        System.out.println("全类名：" + name);
        String simpleName = c.getSimpleName();
        System.out.println("类名：" + simpleName);
        String superName = c.getSuperclass()
                .getSuperclass().getName();
        System.out.println("✌类名：" + superName);
        System.out.println("-------------获取属性Field-------------");
        //可以获取类的所有属性 但是不包括父类的属性
        Field[] fs = c.getDeclaredFields();
        for (Field f : fs) {
            String filaName = f.getName();
            Class type = f.getType();
            System.out.println("属性名：" + filaName + " 类型：" + type);
        }
        System.out.println("-------------------------------");
        //只能获取类中的公开资源（自己和父类）
        Field[] fs1 = c.getFields();
        for (Field f : fs1) {
            String filaName = f.getName();
            Class type = f.getType();
            System.out.println("属性名：" + filaName + " 类型：" + type);
        }
    }
}